﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cofe.Core.Property
{
    public static class PropertyPairExtensions
    {
        public static PropertyPair Find(this PropertyPair[] ppairs, object property)
        {
            try
            {
                return ppairs.First(pp => pp.Property.Equals(property));
            }
            
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine(property);
                CofeServices.Logger.Log(String.Format("Cannot find {0} from PropertyPairs with {1} items", property, ppairs.Count()),
                    Category.Exception, Priority.High);
                throw ex;
            }
        }

        public static PropertyPair TryFind(this PropertyPair[] ppairs, object property)
        {
            return ppairs.FirstOrDefault(pp => pp.Property.Equals(property));
        }

    }
}
